package stars.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/*
 * Holds information on the probability distribution of different system types and the grouping of star within them
 */
public class StarSystemDistributions {
	
	private HashMap<String, Double> probabilities = new HashMap<String, Double>();
	//private HashMap<String, ArrayList<Integer>> starGroupParams = new HashMap<String, ArrayList<Integer>>();
	private ArrayList<String> entries = new ArrayList<String>();
	
	public ArrayList<String> getEntries() {
		return this.entries;
	}
	
	public void addProbability(String param, double value) {
		probabilities.put(param, value);
		entries.add(param);
	}
	
	public double getProbability(String param) {
		return probabilities.get(param);
	}
	
	public HashMap<String, Double> getAllProbabilities() {
		return this.probabilities;
	}
	
	public void setProbabilities(HashMap<String, Double> parameters) {
		this.probabilities.clear();
		this.probabilities.putAll(parameters);
		
		for (Map.Entry<String, Double> entry : parameters.entrySet()) {
			entries.add(entry.getKey());
		}
	}
	
	public void normalize() {
		double cumuProb = 0;
		
		for (String type: entries) {
			cumuProb+=probabilities.get(type);
		}
		
		double correction = 1.0;
		
		if (cumuProb!=1.0) {
			correction = 1/cumuProb;
		}
		
		double correctedProb;
		
		for (String type: entries) {
			correctedProb = probabilities.get(type)*correction;
			probabilities.put(type, correctedProb);
		}
		
	}
	
	
//	public void addStarGroupParam(String param, ArrayList<Integer> groups) {
//		starGroupParams.put(param, groups);
//	}
//	
//	public ArrayList<Integer> getStarGroupParams(String param) {
//		return starGroupParams.get(param);
//	}
//	
//	public HashMap<String, ArrayList<Integer>> getAllStarGroupParams() {
//		return this.starGroupParams;
//	}
//	
//	public void setStarGroupParams(HashMap<String, ArrayList<Integer>> parameters) {
//		this.starGroupParams.clear();
//		this.starGroupParams.putAll(parameters);
//	}

}
